package com.songlanyun.common.supplychainapi.goods;

import com.jxhh.ApiClient;
import com.songlanyun.common.supplychainapi.common.ApiRequestCommon;
import com.songlanyun.common.supplychainapi.goods.model.GoodsCategoryResult;
import com.songlanyun.common.supplychainapi.goods.model.GoodsDetailResult;
import com.songlanyun.common.supplychainapi.goods.model.GoodsPageResult;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Map;

@Component
public class ApiGoodsCommon {

    /**
     * 在线选品v2（新版）
     */
    private static final String NEW_LIST_URL = "/v2/GoodsStorage/NewList";
    /**
     * 获取商品详情v2
     */
    private static final String GOODS_DETAIL_URL = "/v2/Goods/Detail";
    /**
     * 获取逐级类目v2
     */
    private static final String GET_CATEGORY_URL = "/v2/Category/GetCategory";

    @Resource
    private ApiRequestCommon request;

    /**
     * 在线选品的列表
     *
     * @param params {
     *               "page": 0,
     *               "search_words": "string",
     *               "limit": 0,
     *               "source": 0,
     *               "category_id": 0,
     *               "brand_ids": [
     *               0
     *               ],
     *               "agreement_price": {
     *               "from": 0,
     *               "to": 0
     *               },
     *               "guide_price": {
     *               "from": 0,
     *               "to": 0
     *               },
     *               "activity_price": {
     *               "from": 0,
     *               "to": 0
     *               },
     *               "promotion_rate": {
     *               "from": 0,
     *               "to": 0
     *               },
     *               "activity_rate": {
     *               "from": 0,
     *               "to": 0
     *               },
     *               "profits": {
     *               "from": 0,
     *               "to": 0
     *               },
     *               "created_time": {
     *               "from": 0,
     *               "to": 0
     *               },
     *               "type": "string",
     *               "sort": "string",
     *               "is_free_shipping": 0,
     *               "shop_words": "string",
     *               "group_id": 0,
     *               "recommend": 0,
     *               "goods_type": 0
     *               }
     * @return
     * @throws IOException
     */
    public GoodsPageResult questGoodsLists(Map<String, Object> params) {
        return request.exec(NEW_LIST_URL, ApiClient.RequestMethod.POST, params, GoodsPageResult.class, "在线选品");
    }

    /**
     * 获取商品详情
     * id 商品spu id(商品列表中的id字段)
     *
     * @param params
     * @return
     */
    public GoodsDetailResult questGoodsDetail(Map<String, Object> params) {
        return request.exec(GOODS_DETAIL_URL, ApiClient.RequestMethod.GET, params, GoodsDetailResult.class, "获取商品详情");
    }

    /**
     * 获取逐级类目
     *
     * @param params parent_id  默认0代表一级 （父级分类id）
     *               source 来源0聚合分类1云仓2京东6阿里巴巴7天猫11华南一仓14华东一仓15淘宝
     * @return
     */
    public GoodsCategoryResult[] questGoodsCategoryList(Map<String, Object> params) {
        return request.exec(GET_CATEGORY_URL, ApiClient.RequestMethod.GET, params, GoodsCategoryResult[].class, "获取逐级类目");
    }

}
